package secondBrain.gaslog.businessentities;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GasBook {

	private String _name;
	private int _maxId = 1;
	private List<GasRecord> _records = new ArrayList<GasRecord>();
	
	private GasBook(String name) {
		
		_name = name;
	}

	public String getName(){
		
		return _name;
	}
	public static GasBook GetBook(String name) {

		GasBook book = new GasBook(name);
		return book;
	}

	public GasRecord addRecord(GasRecord record) {
		
		record.setId(_maxId);
		_maxId++;
		_records.add(record);
		return record;
		
	}

	public GasRecord findRecordById(Integer id) {
		
		GasRecord record = null;
		Iterator<GasRecord> itr = _records.iterator();

		while(itr.hasNext()){
			GasRecord tempRec = itr.next();
			if (tempRec.getId() == id){
				record = tempRec;
				break;
			}
		}
		return record;
	}

}
